package com.zjt.takeoutproject.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zjt.takeoutproject.common.BaseContext;
import com.zjt.takeoutproject.entity.ShoppingCart;
import com.zjt.takeoutproject.mapper.ShoppingCartMapper;
import com.zjt.takeoutproject.service.ShoppingCartService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 购物车 服务实现类
 * </p>
 *
 * @author jobob
 * @since 2023-07-09
 */
@Service
public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, ShoppingCart> implements ShoppingCartService {

    @Resource
    private ShoppingCartService shoppingCartService;

    @Override
    public void clean() {
        Long currentId = BaseContext.getCurrentId();
        LambdaQueryWrapper<ShoppingCart> cartLambdaQueryWrapper = new LambdaQueryWrapper<>();
        cartLambdaQueryWrapper.eq(ShoppingCart::getUserId,currentId);
        shoppingCartService.remove(cartLambdaQueryWrapper);
    }
}
